package com.dkt.android.api;



import com.dkt.android.utils.PropertyUtils;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * @author: dtb
 * @email: wendaoyuqin1@gmail.com
 * @createTime: 19-3-14上午10:52
 */
class NetClient {
    /**
     * 获取Retrofit适配器。
     *
     * @return 网络适配器
     */
    static Retrofit newRxRetrofit() {
        return new Retrofit.Builder()
                .baseUrl(PropertyUtils.getPropertiesByName(PropertyUtils.BASE_API_URL))
                .client(getClient())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }


    private static OkHttpClient getClient() {
        return new OkHttpClient.Builder()
                .followRedirects(false)
                .followSslRedirects(false)
                .connectTimeout(15, TimeUnit.SECONDS)
                .addInterceptor(new TokenInterceptord())
                .addInterceptor(new LoggerInterceptor("okhttp"))
                .build();
    }
}